package com.shj.service.impl;

import com.shj.dao.SysRoleMenuMapper;
import com.shj.entity.SysRoleMenu;
import com.shj.service.SysRoleMenuService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;

/**
 * @Description 角色权限
 * @Author songhuajian
 * @Date 2020/1/12 23:14
 **/
@Service("sysRoleMenuService")
public class SysRoleMenuServiceImpl implements SysRoleMenuService {

    @Autowired
    private SysRoleMenuMapper sysRoleMenuMapper;

    /**
     * @description 根据权限id查询角色
     * @author songhuajian
     * @date 2020/1/12 23:17
     */
    @Override
    public List<SysRoleMenu> findByPowerId(String powerId){
        return sysRoleMenuMapper.selectByMenuId(powerId);
    }

    @Override
    public boolean hasRole(String roleId, String menuId) {
        if (sysRoleMenuMapper.hasRole(roleId, menuId) != null) {
            return true;
        }
        return false;
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int add(SysRoleMenu sysRoleMenu) {
        return sysRoleMenuMapper.insert(sysRoleMenu);
    }

    @Override
    @Transactional(rollbackFor = Exception.class)
    public int delete(String roleId) {
        return sysRoleMenuMapper.delete(roleId);
    }
}
